package com.fanfanwang.ffw.app.asynctask;

import java.util.LinkedHashMap;

import org.json.JSONException;

import android.app.Activity;
import android.text.TextUtils;
import android.widget.Toast;

import com.fanfanwang.ffw.app.AppConstant;
import com.fanfanwang.ffw.app.bean.SucAddParkNum;
import com.fanfanwang.ffw.app.bean.SucDelParkNum;
import com.fanfanwang.ffw.app.bean.SucParkNumBean;
import com.fanfanwang.ffw.app.common.Md5Util;
import com.fanfanwang.ffw.app.common.ToastAlone;
import com.fanfanwang.ffw.app.net.HttpRequest.HttpRequestException;
import com.fanfanwang.ffw.app.net.IssAsyncTask;
import com.fanfanwang.ffw.app.net.IssNetLib;
import com.fanfanwang.ffw.app.net.WebServiceHelper;
import com.fanfanwang.ffw.app.tenant.R;
import com.fanfanwang.ffw.app.ui.my.GlyMyCarportManagementAct;



public class DelParknumAsyncTask extends IssAsyncTask<String, String, SucDelParkNum> {
	private Activity mActivity;
	private String park_id;
	public DelParknumAsyncTask(Activity activity,String park_id) {
		super(activity);
		mActivity = activity;
		this.park_id = park_id;
	}

	@Override
	protected SucDelParkNum doInBackground(String... params) {
		// TODO 	addAuctionPrice($apiusername,$apipassword,$userid,$pid,$price)
		SucDelParkNum sucDelParkNum = null;
		LinkedHashMap<String, Object> paramsMap = new LinkedHashMap<String, Object>();
		paramsMap.put("apiusername", "parking");
		paramsMap.put("apipassword", Md5Util.getMD5To32("parking"));
		paramsMap.put("park_id", park_id);
		try {
			sucDelParkNum = IssNetLib.getInstance(mActivity).delParknums(WebServiceHelper._DELPARKNUM, paramsMap);
		} catch (HttpRequestException e) {
			e.printStackTrace();
			//			exception = getResources().getString(R.string.e_net_error);
		} catch (JSONException e) {
			e.printStackTrace();
			//			exception = getResources().getString(R.string.e_json);
		}
		return sucDelParkNum;
	}

	@Override
	protected void onPostExecute(SucDelParkNum result) {
		super.onPostExecute(result);
		if (exception != null) {
			ToastAlone.showToast(mActivity, exception);
			return;
		}
		if (result != null) {
			if (result.status == 1) {
				if(!TextUtils.isEmpty(result.msg)){
					ToastAlone.showToast(mActivity, AppConstant.URLDecoderString(result.msg), Toast.LENGTH_SHORT).show();
					GlyMyCarportManagementAct.iDeleteCarportable.deleteSuccess();
					//让这个页面更新一下车位。
					GlyMyCarportManagementAct.iUpdateParknumList.updateParknumList();
				}
			}else if(result.status == 0){
				if(!TextUtils.isEmpty(result.msg)){
					ToastAlone.showToast(mActivity, AppConstant.URLDecoderString(result.msg), Toast.LENGTH_SHORT).show();
				}else{
					ToastAlone.showToast(mActivity, mActivity.getResources().getString(R.string.e_net_error)).show();
				}
			}
		}
	}
}
